<?php
use app\assets\EchartsAsset;
use app\models\KeyMap;
use yii\helpers\Html;
use dosamigos\datepicker\DatePicker;


EchartsAsset::register($this);

$this->title = '充值分析';
$this->params['breadcrumbs'][] = '系统统计';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <label for="search_agentname" class="sr-only">代理商</label>
    <?php echo Html::textInput('search_agentname', Yii::$app->request->get('search_agentname'), ['id' => 'search_agentname', 'class' => 'form-control', 'placeholder' => '代理商', 'style' => 'width: 120px;']);?>
</div>
<div class="form-group">
    <label for="search_trade_type" class="sr-only">支付方式</label>
    <?php echo Html::dropDownList('search_trade_type', Yii::$app->request->get('search_trade_type'), KeyMap::getValues('user_card_recharge_trade_type'), ['id' => 'search_trade_type', 'class' => 'form-control', 'prompt' => '支付方式']);?>
</div>
<div class="form-group">
    <label for="search_recharge_type" class="sr-only">充值状态</label>
    <?php echo Html::dropDownList('search_recharge_type', Yii::$app->request->get('search_recharge_type'), KeyMap::getValues('recharge_type'), ['id' => 'search_recharge_type', 'class' => 'form-control', 'prompt' => '充值状态']);?>
</div>
<div class="form-group">
    <label for="search_status" class="sr-only">来源</label>
    <?php echo Html::dropDownList('search_source', Yii::$app->request->get('search_source'), KeyMap::getValues('source'), ['id' => 'search_source', 'class' => 'form-control', 'prompt' => '来源']);?>
</div>
<div class="form-group">
    <label for="time">开始时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_start_time', 
        'options' => ['placeholder' => '开始时间'], 
        'attribute' => 'time',
        'template' => '{addon}{input}',
        'value' => $last_month,
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>
</div>
<div class="form-group">
    <label for="time">结束时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_end_time', 
        'options' => ['placeholder' => '结束时间'], 
        'attribute' => 'time',
        'template' => '{addon}{input}',
        'value' => $today,
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
</div>
<?php echo Html::endForm();?>
<br/>

<div id="main" style="width: 95%;height:500px;"></div>
	<script type="text/javascript">
		var date = <?php echo $month;?>;
		var recharge = <?php echo json_encode($recharge);?>;
		var renew = <?php echo json_encode($renew);?>;
		var reserve = <?php echo json_encode($reserve)?>;
		var execute = <?php echo json_encode($execute)?>;
		function pageInit(){
			var myChart = echarts.init(document.getElementById('main'),'macarons');
			var legend = [];
			myChart.setOption(getChartsStatusOption());
		}

		function getChartsStatusOption(){
			return {
				title: {
				text: '充值分析',
    		},
			tooltip: {
				trigger: 'axis'
			},
			legend: {
				data: ['首次订购', '续费', '预订购','预订购执行']
			},
			toolbox: {
				show: true,
				feature: {
					dataView: {show: true, readOnly: false},
					magicType: {show: true, type: ['line', 'bar']},
					restore: {show: true},
					saveAsImage: {show: true}
				}
			},
			calculable: true,
			xAxis: [
				{
					type: 'category',
					data: date
				}
			],
			yAxis: [
				{
					type: 'value'
				}
			],
			series: [
				{
					name: '首次订购',
					type: 'bar',
					data: recharge,
				},
				{
					name: '续费',
					type: 'bar',
					data: renew,
				},
				{
					name: '预订购',
					type: 'bar',
					data: reserve,
				},
				{
					name: '预订购执行',
					type: 'bar',
					data: execute,
				}
			]
			}
		}
	</script>
	
